package cn.yangliu.webflux.tools;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Properties;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomUtils;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.AbstractUUIDGenerator;
import org.hibernate.id.Configurable;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.Type;

/**
 * @author 杨柳
 * @date 2019-05-17
 */

@Slf4j
public class IdGenerator extends AbstractUUIDGenerator implements Configurable {

  /*  private String dataCenterID;
    private String idLength;*/

    @Override
    public void configure(Type type, Properties properties, ServiceRegistry serviceRegistry) throws MappingException {
     /*   this.dataCenterID = properties.getProperty("dataCenterID");
        this.idLength = properties.getProperty("idLength");*/

    }

    @Override
    public Serializable generate(SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws HibernateException {
        long id = SnowflakeIdWorker.generateId() + RandomUtils.nextLong(0, 2);
        log.info("-------------------" + id);
        return id;
    }
}
